package com.qj.yantaishan.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.IService;
import com.qj.yantaishan.common.core.domain.R;
import org.apache.ibatis.annotations.Delete;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.ProductCategory;
import com.qj.yantaishan.service.IProductCategoryService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 商品分类Controller
 *
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/ProductCategory")
public class ProductCategoryController extends BaseController {
    private String prefix = "yantaishan/ProductCategory";

    @Autowired
    private IProductCategoryService productCategoryService;

    @GetMapping("list")
    public R list() {
        List<ProductCategory> categoryList = productCategoryService.myList();
        return R.ok(categoryList);
    }

    @PutMapping("update")
    public R update(@RequestBody ProductCategory category) {
        productCategoryService.updateById(category);
        return R.ok("更新成功");
    }

    @DeleteMapping("delete")
    public R delete(@RequestParam Long catId) {
        productCategoryService.removeById(catId);
        return R.ok("删除成功");
    }

    @PostMapping("save")
    public R save(@RequestBody ProductCategory productCategory) {
        productCategory.setCatStatus(1);
        productCategory.setAgentId("8581960447");
        productCategory.setStoreId(1);
        productCategoryService.save(productCategory);
        return R.ok("保存成功");
    }
}
